package com.example.wanandroid.mapper;

import com.example.wanandroid.pojo.Answer;
import com.example.wanandroid.pojo.Question;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

@Component
public interface AnswerMapper {
    int deleteByPrimaryKey(Long id);

    int insert(Answer record);

    int insertSelective(Answer record);

    Answer selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Answer record);

    int updateByPrimaryKey(Answer record);

    @Select("SELECT a.id AS answerId,a.userid,a.question_id AS questionId,a.content AS answerContent,a.create_date AS createDate, q.`content` AS questionContent ,q.`title` AS title FROM tb_answer a LEFT JOIN tb_question q ON a.`question_id`=q.`id` " +
            "WHERE a.userid = 1 ORDER BY a.id DESC LIMIT #{start},#{pageSize}")
    List<HashMap<String,Object>> listMyAnswers(Long userid, int start, int pageSize);

    @Select("SELECT a.id AS answerId,a.userid,a.question_id AS questionId,a.content AS answerContent,a.create_date AS createDate ,u.`nickname`,u.`icon` " +
            "FROM tb_answer a " +
            "LEFT JOIN tb_question q ON a.`question_id`=q.`id` LEFT JOIN tb_user u ON a.`userid`=u.`id` " +
            "WHERE a.question_id = #{questionId}  " +
            "ORDER BY a.id DESC LIMIT #{start},#{pageSize}")
    List<HashMap<String,Object>> listAnswersByQuestionId(Long questionId, int start, int pageSize);
}